package com.starmark.gateway.project.provider.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.starmark.core.framework.base.AbstractBaseService;
import com.starmark.gateway.project.provider.entity.GatewayAppMachine;
import com.starmark.gateway.project.provider.mapper.GatewayAppMachineMapper;
import com.starmark.gateway.project.provider.service.IGatewayAppMachineService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author starmark
 * @since 2020-01-24
 */
@Service
public class GatewayAppMachineServiceImpl extends AbstractBaseService<GatewayAppMachineMapper, GatewayAppMachine> implements IGatewayAppMachineService {


    @Override
    public void buildPageSearch(Map<String, Object> params, QueryWrapper<GatewayAppMachine> eWrapper) {
        if (params.get("keyword") != null && StrUtil.isNotEmpty(params.get("keyword") + "")) {
            eWrapper.like("name", params.get("keyword") + "");
        }

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteMachinesByAppId(String appId) {
        Assert.hasText(appId,"应用ID不允许为空!");
        this.baseMapper.deleteMachinesByAppId(appId);
    }

    @Override
    public List<GatewayAppMachine> getMachineListByAppId(String appId) {
        Assert.hasText(appId,"应用ID不允许为空!");
        return   this.baseMapper.getMachineListByAppId(appId);
    }
}
